import qs from "qs"
import axios from "axios"
import { Message, MessageBox } from "element-ui"
import { isTrimValidString } from "@/utils/data"
// 创建一个 axios 实例
const instance = axios.create({
	// baseURL: app.services,
	timeout: 10000, // 请求超时时间
})

// 请求拦截器
instance.interceptors.request.use(
	config => {
		return config
	},
	error => {
		return Promise.error(error)
	},
)

// 响应拦截器
instance.interceptors.response.use(
	response => {
		return Promise.resolve(response)
	},
	error => {
		Message({
			message: _.isPlainObject(error.response)
				? isTrimValidString(error.response.data)
					? error.response.data
					: error.response.statusText
				: error.message,
			dangerouslyUseHTMLString: true,
			type: "error",
			duration: 3000,
		})
		return Promise.reject(error)
	},
)

export default instance
